package com.jky.filesystem.utils;

import com.jky.filesystem.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

public class ToastDialogUtils {

    public static void showDialog(Context context, String text) {
        DirectionalLayout toastLayout = (DirectionalLayout) LayoutScatter.getInstance(context).parse(ResourceTable.Layout_layout_toast, null, false);
        if (toastLayout.findComponentById(ResourceTable.Id_msg_toast) instanceof Text) {
            ((Text) toastLayout.findComponentById(ResourceTable.Id_msg_toast)).setText(text);
            new ohos.agp.window.dialog.ToastDialog(context)
                    .setComponent((Component) toastLayout)
                    .setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT)
                    .show();
        }
    }

}
